/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogImprimirTraz.java
 *
 * Created on 16/05/2011, 17:23:12
 */
package vistas.dialogs;

import com.sun.corba.se.impl.orb.ParserTable.TestAcceptor1;
import comu.Configuracio;
import comu.Utilitats;
import controlador.CollitaControlador;
import entity.Collita;
import java.awt.print.PrinterException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.PrintException;
import vistas.textImg.Textos;

/**
 *
 * @author David
 */
public class DialogImprimirTraz extends javax.swing.JDialog {

    CollitaControlador collites;
    String producte;
    String traz;
    String data;
    String quantitat;
    /** Creates new form DialogImprimirTraz */
    public DialogImprimirTraz(java.awt.Frame parent, boolean modal,Collita collita) {
        super(parent, modal);
        collites = new CollitaControlador();
        this.producte = collita.getProduccioId().getProductesId().getNom();
        this.traz = collites.getTrazabilitatCode(collita);
        this.data = Configuracio.sdf.format(collita.getData());
        this.quantitat = String.valueOf(collita.getQuantitat())+" "+collita.getUnitatsMesuraId().getNom();
        initComponents();
        Utilitats.centrarVentana(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbMisatge = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btImprimir = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        lbTrazCode = new javax.swing.JLabel();
        lbQuantitat = new javax.swing.JLabel();
        lbData = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lbMisatge.setText(Textos.DIALOGIMPRIMIRTRAZ_INFO_IMPRIMIR);

        jLabel2.setText(Textos.DIALOGIMPRIMIRTRAZ_NOM_QUANTITAT);

        jLabel3.setText(Textos.DIALOGIMPRIMIRTRAZ_NOM_DATA);

        btImprimir.setText(Textos.DIALOGIMPRIMIRTRAZ_BOTO_IMPRIMIR);
        btImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btImprimirActionPerformed(evt);
            }
        });

        btCancelar.setText(Textos.DIALOGIMPRIMIRTRAZ_BOTO_CANCEL);
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        lbTrazCode.setText(this.traz);

        lbQuantitat.setText(this.quantitat);

        lbData.setText(this.data);

        jLabel4.setText(Textos.DIALOGIMPRIMIRTRAZ_NOM_TRAZCODE);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(95, 95, 95)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel4)
                            .add(jLabel3)
                            .add(jLabel2))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(lbData)
                            .add(lbTrazCode)
                            .add(lbQuantitat)))
                    .add(layout.createSequentialGroup()
                        .add(30, 30, 30)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(lbMisatge)
                            .add(layout.createSequentialGroup()
                                .add(btImprimir, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(btCancelar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(29, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(lbTrazCode))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(lbQuantitat))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(lbData))
                .add(6, 6, 6)
                .add(lbMisatge)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btImprimir, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btCancelar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btCancelarActionPerformed

    private void btImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btImprimirActionPerformed
        try {
            Utilitats.Imprimir(producte,data,quantitat,traz);
        } catch (PrinterException ex) {
            Logger.getLogger(DialogImprimirTraz.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.setVisible(false);
    }//GEN-LAST:event_btImprimirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btImprimir;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lbData;
    private javax.swing.JLabel lbMisatge;
    private javax.swing.JLabel lbQuantitat;
    private javax.swing.JLabel lbTrazCode;
    // End of variables declaration//GEN-END:variables
}
